package com.jch.dm.chapter_10_strategy;

/**
 * @author: jch
 * 策略模式 示例 玩家类
 **/
public class Player {

    private String name;
    private Strategy strategy;
    private int winCount;
    private int loseCount;
    private int gameCount;

    public Player(String name, Strategy strategy) {
        this.name = name;
        this.strategy = strategy;
    }

    /**
     * 下一个手势
     *
     * @return hand
     */
    public Hand nextHand() {
        return strategy.nextHand();
    }

    /**
     * 胜
     */
    public void win() {
        strategy.study(true);
        winCount++;
        gameCount++;
    }

    /**
     * 负
     */
    public void lose() {
        strategy.study(false);
        loseCount++;
        gameCount++;
    }

    /**
     * 平
     */
    public void even() {
        gameCount++;
    }

    @Override
    public String toString() {
        return "[" + name + "：" + gameCount + " games," + winCount + " win," + loseCount + " lose]";
    }
}
